package com.mvprxjavartrofit.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.mvprxjavartrofit.base.util.TUtil;

import butterknife.Unbinder;

/**
 * Created by Administrator
 * At 2016/10/20/10:13/2016
 * Project test
 */
public abstract class BaseActivity<T extends BasePresenter, E extends BaseModel> extends AppCompatActivity{
    public T presenter;
    public E model;
    public Context context;

    protected Unbinder unbinder;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(getLayoutId());
        context = this;
        presenter = TUtil.getT(this, 0);
        model = TUtil.getT(this, 1);
        this.initView();
        if(this instanceof BaseView){
            presenter.setVM(this, model);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(presenter != null){
            presenter.onDestroy();
        }
        if(unbinder != null){
            unbinder.unbind();
        }
    }

    public abstract int getLayoutId();

    public abstract void initView();
}
